package com.fatcat.easybuy.service.impl;

import com.fatcat.easybuy.mapper.EasyBuyUserAddressMapper;
import com.fatcat.easybuy.pojo.EasyBuyUserAddress;
import com.fatcat.easybuy.service.EasyBuyUserAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Fatcat
 * @description 针对表【easybuy_user_address】的数据库操作Service实现
 * @createDate 2025-09-10 11:11:58
 */
@Service
public class EasyBuyUserAddressServiceImpl implements EasyBuyUserAddressService {
    @Autowired
    private EasyBuyUserAddressMapper easyBuyUserAddressMapper;


    @Override
    public boolean setDefaultAddress(Long userId, Integer id) {
        easyBuyUserAddressMapper.setAllAddressNotDefault(userId);
        if (easyBuyUserAddressMapper.setDefault(id) == 1) {
            return true;
        }
        return false;
    }

    @Override
    public List<EasyBuyUserAddress> getAllAddressByUserid(Long userId) {
        return easyBuyUserAddressMapper.selectUserAddressByUserId(userId);
    }

    @Override
    public boolean addUserAddress(EasyBuyUserAddress easyBuyUserAddress) {
        return easyBuyUserAddressMapper.addUserAddress(easyBuyUserAddress) == 1;
    }

    @Override
    public String getAddressById(Integer id) {
        EasyBuyUserAddress easyBuyUserAddress = easyBuyUserAddressMapper.selectAddressById(id);
        String address = easyBuyUserAddress.getAddress() + easyBuyUserAddress.getDetailedAddress();
        return address;
    }

    @Override
    public boolean updateUserAddress(EasyBuyUserAddress easyBuyUserAddress) {
        return easyBuyUserAddressMapper.updateAddress(easyBuyUserAddress) == 1;
    }

    @Override
    public boolean deleteUserAddress(Integer id) {
        return easyBuyUserAddressMapper.deleteAddress(id) == 1;
    }

    @Override
    public Integer selectAddressCountOfUser(Long userId) {
        return easyBuyUserAddressMapper.selectAddressCountOfUser(userId);
    }
}




